<template>
	<!-- 右上角的工具栏 -->
	<view class="box">
		<view class="box-item"><uni-icons type="gift-filled" size="16" color="#ff6f71" class="icon"></uni-icons>活动</view>
		<view class="box-item"><uni-icons type="vip-filled" size="16" color="#f1ec5c" class="icon"></uni-icons>排行</view>
		<view class="box-item"><uni-icons type="email-filled" size="16" color="#fff" class="icon"></uni-icons>邮件</view>
		<view class="box-item" @click="gameSet"><uni-icons type="gear-filled" size="16" color="#fff" class="icon"></uni-icons>设置</view>
		
		<!-- 遮罩加弹框效果 -->
		<view class="game-set" v-if="gameZz" @click="closeZz"></view>
		<view class="con" v-if="gameZz">
			<view class="con-tit">游戏设置</view>
			<view class="con-sex">
				<uni-data-checkbox @change="change" :localdata="sex" mode="button" :value="sexValue"></uni-data-checkbox>
			</view>
			<view class="st-btn" @click="stopGame">退出游戏</view>
		</view>
		
		<uni-popup ref="popup" type="message">
			<uni-popup-message type="success" class="success-text">修改成功</uni-popup-message>
		</uni-popup>
	</view>
</template>

<script>
import audioManager from '@/utils/audioManager.js';
import {getUserInfo,updateSex} from "@/api/index";


export default{
	name:"RightTools",
	data(){
		return{
			gameZz:false,
			sex: [{
				text: '男',
				value: 0
			}, {
				text: '女',
				value: 1
			}],
			sexValue:""
		}
	},
	mounted(){
		this.getUserSex();
	},
	methods:{
		stopGame(){
			uni.clearStorageSync();
			uni.reLaunch({
				url:"/pages/login/login"
			})
		},
		getUserSex(){
			let userInfo = wx.getStorageSync("userInfo");
			console.log("userInfo",userInfo.sex);
			if(userInfo.sex == "男"){
				this.sexValue = 0;
			}else{
				this.sexValue = 1;
			}
			
		},
		change(e){
			console.log(e.detail.value);
			let data = {
				"sex":e.detail.value
			}
			updateSex(data).then((res)=>{
				console.log(res);
				//提示
				this.$refs.popup.open('top');
				getUserInfo().then((data)=>{
					uni.setStorageSync("userInfo",data.data);
				})
			});
		},
		gameSet(){
			console.log(123);
			audioManager.playAudio('btn_music', false);
			this.gameZz = true;
		},
		closeZz(){
			this.gameZz = false;
		}
	}
}
	
</script>

<style scoped>
.success-text {
	color: #5df583;
	text-align: center;
}
	
.box{
	width: 300px;
	height: 40px;
	display: flex;
	background-color: rgba(0, 0, 0, 0.4);
	border-radius: 5px;
}
.box-item{
	width: 25%;
	height: 40px;
	text-align: center;
	line-height: 40px;
	font-size: 12px;
}
.icon{
	margin-right: 2px;
	position: relative;
	top: 1px;
}

.game-set{
	width: 100%;
	height: 100vh;
	position: fixed;
	left: 0;
	top: 0;
	z-index: 8;
	background-color: rgba(0, 0, 0, 0.5);
}
.con{
	width: 300px;
	height: 150px;
	background-color: #ffff;
	border-radius: 10px;
	position: fixed;
	left: 0;
	right: 0;
	top: 0;
	bottom: 0;
	margin: auto;
	z-index: 9;
}
.con-tit{
	width: 100%;
	height: 30px;
	line-height: 30px;
	text-align: center;
	color: #000;
}
.con-sex{
	width: 135px;
	margin: 0 auto;
	margin-top: 10px;
}
.st-btn{
	width: 90%;
	height: 40px;
	line-height: 40px;
	text-align: center;
	background-color: brown;
	color: #fff;
	margin: 0 auto;
	margin-top: 20px;
}
</style>